# -*- coding: UTF-8 -*-
from Utiles.SendMethod import SendMethod
from Interface.UserInterface.LogInterface import LoginInterface
from Utiles.GetKeywords import GetKeywords

class MemberInterface(object):

    def __init__(self, headers):
        self.url = "http://192.168.10.150"
        self.headers = headers
    def add_member(self, supplier,telephone=None):
        url = self.url + "/jshERP-boot/supplier/add"
        method = "post"
        payload = {"supplier": supplier, "contacts": "123456", "telephone": telephone, "phoneNum": "123456", "email": "123456",
         "type": "会员"}
        return SendMethod.send_method(url=url, method=method, json=payload, headers=self.headers)
    def del_member(self,del_id):
        url = self.url + f"/jshERP-boot/supplier/delete?id={del_id}"
        method = "delete"
        return SendMethod.send_method(url=url, method=method, headers=self.headers)
    def find_member(self):
        url = self.url + "/jshERP-boot/supplier/list?search=%7B%22supplier%22:%22%22,%22type%22:%22%E4%BC%9A%E5%91%98%22,%22telephone%22:%22%22,%22phonenum%22:%22%22%7D&column=createTime&order=desc&field=id,,,action,supplier,contacts,telephone,phoneNum,email,advanceIn,sort,enabled&currentPage=1&pageSize=10"
        method = "get"
        return SendMethod.send_method(url=url, method=method, headers=self.headers)

if __name__ == '__main__':
    res = LoginInterface().tenant_login("jsh", "123456")
    token = GetKeywords.get_keyword(res, "token")
    headers = {"x-access-token": token}
    member = MemberInterface(headers)
    print(member.find_member())
